//index.js
//获取应用实例
const app = getApp()
const Pager = require('components/aotoo/core')
let lib = Pager.lib

let mkSearch = require('components/modules/search')
const defaultAdapter = require('../../utils/default')
const xxx = defaultAdapter({title: '暂无数据', image: '/images/cat.png'})
const xxx2 = defaultAdapter({title: '网络出错，请刷新重试', image: '/images/cat.png'})

Pager({
  data: {
    itemx: null,
    itemx2: Pager.item({
      title: [{title: ' ', itemClass: 'icon-search'}, {title: '搜索', itemClass: 'ml-minor'}],
      titleClass: 'flex-row-center-center',
      itemClass: 'ss-search-false',
      aim: 'onClick'
    })
  },
  onClick() {
    this.setData({
      itemx: mkSearch({
        placeholder: '请输入关键字1或2,或任意',
        // btnText: '提交',
        // focus: true,
        adapter(data, id){
          return data.map(item => {
            return {
              '@html': {
                content: item.title,
                listClass: 'xxss'
              },
              dot: item.type === 'address' ? [{
                title: '目的地',
                itemClass: 'size-sm color-disable'
              }] : [],
              id: item.id,
              itemClass: 'item-rc ai-center',
              aim: item.aim || item.tap
            }
          })
        },
        btnCb(val, listInst, adapter){
          if (val === '1') {
            listInst.update([xxx])
          }
          else if (val === '2') {
            listInst.update([xxx2])
          }
          else {
            const _newData = adapter([{title: '周末吃什么好呢'},{title: '周末吃<span style="color: #FF6B1F">中山黄油蟹私房美食</span>xx'},{title: '中山', type: 'address'},{title: '请输入1，显示没什么数据'},{title: '请输入2，显示网络错误'}])
            listInst.update({data:  _newData})
          }
        },
        formCls: '',
        listCls: '',
      }),
      itemx2: null
    })
  },
  onLoad() {
  }
})